const RouterHook = require("../module/routerModule")
const { addChargePilePay,
    updateChargePilePay,
    deleteChargePilePay,
    getChargePilePayList } = require("../service/adminChargingStationsPay")
const { AssertUtils } = require("../util/utils")
const {query} = require("../util/dbutil");
const router = RouterHook()

/**
 * @swagger
 * /admin/charging/stations/pay/getList:
 *    get:
 *      tags:
 *      - 管理后台充电桩订单
 *      summary: 获取充电桩订单列表
 *      produces:
 *      - application/json
 *      parameters:
 *        - name: id
 *          description: 充电桩订单id
 *          required: false
 *          type: number
 *        - name: user_id
 *          description: 充电桩订单用户id
 *          required: false
 *          type: number
 *        - name: status
 *          description: 充电桩订单状态
 *          required: false
 *          type: number
 *      responses:
 *        200:
 *          description: 返回充电桩订单列表
 *          schema:
 *            type: object
 *            properties:
 *              data:
 *                type: array
 *                default: [
 *                    {
 *                      "id":1,
 *                      "status": 1,
 *                      "user_id": 100,
 *                      "amount": 10,
 *                   }
 *                ]
 *        401:
 *          description: 参数错误
 * */
router.get("/getList", async (ctx) => {
    const q = ctx.request.query
    const {data,result} = await getChargePilePayList(q)
    ctx.body = {
        code:200,
        data,
        total:result[0].count
    }
}).noAuth()

/**
 * @swagger
 * /admin/charging/stations/pay/add:
 *    post:
 *      tags:
 *      - 管理后台充电桩订单
 *      summary: 新增充电桩订单
 *      produces:
 *      - application/json
 *      parameters:
 *        - name: name
 *          description: 订单名
 *          required: true
 *          type: string
 *        - name: money
 *          description: 消费金额
 *          required: true
 *          type: number
 *        - name: minute
 *          description: 充电时间(分钟)
 *          required: true
 *          type: number
 *      responses:
 *        200:
 *          description: 返回信息
 *          schema:
 *            type: object
 *            properties:
 *              data:
 *                type: array
 *                default: [
 *                    {
 *                      "message":"添加成功",
 *                   }
 *                ]
 *        401:
 *          description: 参数错误
 * */
router.post("/add", async (ctx) => {
    const body = ctx.request.body
    await addChargePilePay(body)

    ctx.body = {
        code:200,
        message:'添加成功'
    }
}).noAuth()
/**
 * @swagger
 * /admin/charging/stations/pay/update:
 *    post:
 *      tags:
 *      - 管理后台充电桩订单
 *      summary: 修改充电桩订单列表
 *      produces:
 *      - application/json
 *      parameters:
 *        - name: id
 *          description: 订单id
 *          required: required
 *          type: number
 *        - name: name
 *          description: 订单名称
 *          required: false
 *          type: string
 *        - name: address
 *          description: 订单金额
 *          required: false
 *          type: string
 *        - name: voltage
 *          description: 充电时长(分钟)
 *          required: false
 *          type: string
 *        - name: status
 *      responses:
 *        200:
 *          description: 返回信息
 *          schema:
 *            type: object
 *            properties:
 *              data:
 *                type: array
 *                default: [
 *                    {
 *                      "message":"修改成功",
 *                   }
 *                ]
 *        401:
 *          description: 参数错误
 * */
router.post("/update", async (ctx) => {
    const body = ctx.request.body
    await updateChargePilePay(body)
    ctx.body = {
        code:200,
        message:'修改成功'
    }
}).noAuth()
/**
 * @swagger
 * /admin/charging/stations/pay/delete:
 *    post:
 *      tags:
 *      - 管理后台充电桩订单
 *      summary: 删除充电桩订单
 *      produces:
 *      - application/json
 *      parameters:
 *        - name: id
 *          description: 订单id
 *          required: required
 *          type: number
 *      responses:
 *        200:
 *          description: 返回信息
 *          schema:
 *            type: object
 *            properties:
 *              data:
 *                type: array
 *                default: [
 *                    {
 *                      "message":"删除成功",
 *                   }
 *                ]
 *        401:
 *          description: 参数错误
 * */
router.post("/delete", async (ctx) => {
    const { id } = ctx.request.body
    AssertUtils.StringNotEmpty(id, "请输入id")
    await deleteChargePilePay(id)
    ctx.body = {
        code:200,
        message:'删除成功'
    }
})


module.exports = router
